package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_Fanout {

    public static final String Exchange_Fanout_1 = "Exchange_Fanout_1";

    public static final String Queue_Fanout_1 = "Queue_Fanout_1";
    public static final String Queue_Fanout_2 = "Queue_Fanout_2";
    public static final String Queue_Fanout_3 = "Queue_Fanout_3";


    @Bean(Exchange_Fanout_1)
    public Exchange exchange_Fanout_1(){
        return ExchangeBuilder.fanoutExchange(Exchange_Fanout_1).build();
    }

    @Bean(Queue_Fanout_1)
    public Queue queue_Fanout_1(){
        return QueueBuilder.durable(Queue_Fanout_1).build();
    }

    @Bean(Queue_Fanout_2)
    public Queue queue_Fanout_2(){
        return QueueBuilder.durable(Queue_Fanout_2).build();
    }

    @Bean(Queue_Fanout_3)
    public Queue queue_Fanout_3(){
        return QueueBuilder.durable(Queue_Fanout_3).build();
    }

    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_fanout_1(
            @Qualifier(Queue_Fanout_1) Queue queue,
            @Qualifier(Exchange_Fanout_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("abcsds").noargs();
    }

    @Bean
    public Binding binding_fanout_2(
            @Qualifier(Queue_Fanout_2) Queue queue,
            @Qualifier(Exchange_Fanout_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("bgdd").noargs();
    }

    @Bean
    public Binding binding_fanout_3(
            @Qualifier(Queue_Fanout_3) Queue queue,
            @Qualifier(Exchange_Fanout_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

}
